package com.pzh.guli.service.oss.controller.admin;

import com.pzh.guli.service.base.result.Result;
import com.pzh.guli.service.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@Api("文件上传")
@RestController
@RequestMapping("admin/oss/file")
public class FileController {

    @Autowired
    private FileService fileService;
    @ApiOperation("文件上传功能")
    @PostMapping("upload")
   public Result upload(@ApiParam("文件名") @RequestParam MultipartFile file,@ApiParam("文件目录模块") @RequestParam String module) throws IOException {
        InputStream inputStream = file.getInputStream();
        String filename = file.getOriginalFilename();
        String url = fileService.upload(inputStream, module, filename);
        return Result.ok().data("url",url).message("文件上传成功");
   }
   @DeleteMapping("remove")
   public Result removeFileByString(@RequestBody String url){
        fileService.removeFile(url);
        return Result.ok().message("文件删除成功");
   }
}
